<?php
// 桌面图标
function __the_core_apps($apps) {
	// 我的网站
	$apps [] = array ('id' => "website", 'url' => ADMIN_URL . 'vfs/', 'cls' => 'icon_site', 'name' => '我的网站', 'tip' => '我的网站', 'icon' => ADMIN_URL . 'images/icons/site.png' );
	// 附件图片
	$apps [998] = array ('id' => "attach", 'url' => ADMIN_URL . 'share/', 'cls' => 'icon_attach', 'name' => '附件图片', 'tip' => '附件图片', 'icon' => ADMIN_URL . 'images/icons/attach.png' );
	// 控制面板
	$apps [999] = array ('id' => "dashboard", 'url' => ADMIN_URL . 'dashboard/', 'cls' => 'icon_cp', 'name' => '控制面板', 'tip' => '控制面板', 'icon' => ADMIN_URL . 'images/icons/cp.png' );
	
	return $apps;
}
bind ( 'get_desktop_applications', '__the_core_apps', 1 );
// 控制面板程序
function __the_core_settings($settings) {
	// 用户管理
	$settings [] = array ('id' => "users", 'url' => ADMIN_URL . 'users/', 'icon' => ADMIN_URL . 'images/icons/users.png', 'cls' => 'icon_users', 'name' => '用户账户' );
	// 用户组管理
	$settings [] = array ('id' => "groups", 'url' => ADMIN_URL . 'group/', 'icon' => ADMIN_URL . 'images/icons/group.png', 'cls' => 'icon_group', 'name' => '用户组' );
	// 用户组管理
	$settings [] = array ('id' => "vip", 'url' => ADMIN_URL . 'vip/', 'icon' => ADMIN_URL . 'images/icons/vip.png', 'cls' => 'icon_vip', 'name' => '会员管理' );
	
	// 分类管理
	$settings [] = array ('id' => "cate", 'url' => ADMIN_URL . 'vfs/?Ctlr=Category', 'icon' => ADMIN_URL . 'images/icons/category.png', 'cls' => 'icon_cate', 'name' => '分类管理' );
	
	// 主题模板
	$settings [] = array ('id' => "themes", 'url' => ADMIN_URL . 'theme/', 'icon' => ADMIN_URL . 'images/icons/theme.png', 'cls' => 'icon_theme', 'name' => '主题模板' );
	
	$settings [] = array ('id' => 'pluginmgr', 'url' => ADMIN_URL . 'dashboard/?Ctlr=PluginMgr', 'icon' => ADMIN_URL . 'images/icons/plugin.png', 'cls' => 'icon_plugin', 'name' => '插件与扩展' );
	
	// 个人选项
	$settings [] = array ('id' => "userinfo", 'url' => ADMIN_URL . 'users/?Ctlr=UserInfo', 'icon' => ADMIN_URL . 'images/icons/key.png', 'cls' => 'icon_key', 'name' => '个人选项' );
	
	// 系统选项
	$settings [999] = array ('id' => "option", 'url' => ADMIN_URL . 'dashboard/?Ctlr=Options', 'icon' => ADMIN_URL . 'images/icons/system.png', 'cls' => 'icon_system', 'name' => '系统选项' );
	return $settings;
}
bind ( 'get_dashboard_settings', '__the_core_settings', 1 );
// 初始化右上角快捷操作
function __the_core_shortcuts() {
	global $__cache;
	echo '<a href="' . ADMIN_URL . 'logout.php" class="ico ico_exit">退出</a>';
	if (has_hook ( "get_cache_driver" )) {
		echo '<a href="#" id="clear_cache" class="ico ico_clear">清缓存</a>';
	}
}
bind ( 'show_shortcuts', '__the_core_shortcuts', 1, 0 );
function __ajax_clear_cache($rst) {
	cache_clear ( true, '' );
	$rst ['success'] = true;
	return $rst;
}
bind ( 'ajax_clear_cache', '__ajax_clear_cache' );

// 初始化smarty引擎
function __the_core_init_smarty_view_engine($smarty) {
	$smarty->assign ( 'core_version', IMS_VER );
	$smarty->assign ( 'nutzp_version', NUTZP_VER . '.' . NUTZP_SUB_VER . '-' . NUTZP_RELEASE );
	$smarty->assign ( '_BASEURL', BASE_URL );
	$smarty->assign ( '_PASSPORT', whoami () );
	return $smarty;
}
bind ( 'init_smarty_view_engine', '__the_core_init_smarty_view_engine' );
// 用户网页类型
function _custom_page_types($types) {
	$tM = new WebPageTypeModel ();
	$types ['page'] = '普通页面';
	$types ['category'] = '频道栏目页';
	$ctypes = $tM->retrieve ( 'page_type,page_type_name' );
	if ($ctypes) {
		foreach ( $ctypes as $ty ) {
			$types [$ty ['page_type']] = $ty ['page_type_name'];
		}
	}
	$types ['template'] = '模板页';
	$types ['index'] = '主页';
	return $types;
}
bind ( 'get_page_types', '_custom_page_types', 100 );
function _custom_content_modes($modes) {
	$modes ['default'] = '普通内容';
	$modes ['category'] = '频道栏目';
	return $modes;
}
bind ( 'get_content_mode', '_custom_content_modes', 1 );
// 新增弹出菜单项
function _new_content_menu($menus) {
	$ap = ADMIN_URL;
	$menus .= '<li><a href="' . $ap . 'vfs/?Ctlr=Menu&op=add"><i class="icon-globe"></i>导航菜单</a></li>';
	$menus .= '<li><a href="' . $ap . 'fragment/?Ctlr=AddFrag"><i class="icon-list-alt"></i>代码片断</a></li>';
	$menus .= '<li><a href="' . $ap . 'link/?Ctlr=AddLink"><i class="icon-retweet"></i>友情链接</a></li>';
	$menus .= '<li><a href="' . $ap . 'vfs/?Ctlr=Page"><i class="icon-file"></i>普通网页</a></li>';
	$menus .= '<li><a href="' . $ap . 'vfs/?Ctlr=Page&ctype=template"><i class="icon-file"></i>模板页</a></li>';
	return $menus;
}
bind ( 'new_content_menu', '_new_content_menu' );
// 我的网站中的标签
function _web_content_navi($navis, $navi) {
	$ap = ADMIN_URL;
	$navis .= '<li class="' . ($navi == 'index' ? 'active' : '') . '"><a href="' . $ap . 'vfs/"><i class="icon-home"></i>网站页面</a></li>';
	$navis .= '<li class="' . ($navi == 'comment' ? 'active' : '') . '"><a href="' . $ap . 'comment/"><i class="icon-comment"></i>评论</a></li>';
	$navis .= '<li class="' . ($navi == 'menu' ? 'active' : '') . '"><a href="' . $ap . 'vfs/?Ctlr=Menu"><i class="icon-globe"></i>导航菜单</a></li>';
	$navis .= '<li class="' . ($navi == 'fragment' ? 'active' : '') . '"><a href="' . $ap . 'fragment/"><i class="icon-list-alt"></i>代码片断</a></li>';
	$navis .= '<li class="' . ($navi == 'links' ? 'active' : '') . '"><a href="' . $ap . 'link/"><i class="icon-retweet"></i>友情链接</a></li>';
	$navis .= '<li class="' . ($navi == 'tags' ? 'active' : '') . '"><a href="' . $ap . 'tags/"><i class="icon-tags"></i>标签</a></li>';
	$navis .= '<li class="' . ($navi == 'enum' ? 'active' : '') . '"><a href="' . $ap . 'enum/"><i class="icon-book"></i>枚举</a></li>';
	return $navis;
}
bind ( 'web_content_navi', '_web_content_navi', 10, 2 );
// 常用枚举值
function get_web_enums($enums) {
	$enums ['author'] = '作者';
	$enums ['source'] = '来源';
	$enums ['keyword'] = '关键词';
	return $enums;
}
bind ( 'get_web_enums', 'get_web_enums' );
// 组类型
function get_group_types($types) {
	$types ['user'] = '用户组';
	$types ['vip'] = '会员组';
	return $types;
}
bind ( 'get_group_types', 'get_group_types' );
// rbac driver
function _basic_rbac_impl($_rbac) {
	if (! $_rbac) {
		return new CentImsRbacImpl ();
	}
	return $_rbac;
}
bind ( 'get_rbac_driver', '_basic_rbac_impl' );

bind ( 'get_rbac_resources', '_core_rbac_resources', 1 );
// 用户组
function _core_get_roles_for_user($types, $uid) {
	$cgu = new CoreGroupUserModel ();
	$groups = $cgu->where ( array ('uid' => $uid ) )->retrieve ( 'gid' );
	
	if ($groups) {
		$types ['GROUP'] = $groups->join ( 'gid', false, ',' );
	}
	
	return $types;
}
bind ( 'get_roles_for_USER', '_core_get_roles_for_user', 1, 2 );
/**
 * 填充护照
 *
 * @param Passport $passort        	
 */
function _core_for_user_passort($passort) {
	$user = sess_get ( '__CUR_USER__', false );
	if ($user) {
		$passort->uid = $user ['uid'];
		$passort->account = $user ['uname'];
		$passort->name = $user ['name'];
		$passort->email = $user ['email'];
		$passort->signed = true;
		$passort->type = $user ['type'];
		$passort->login_ip = $user ['login_ip'];
		$passort->login_time = $user ['login_time'];
	}
	return $passort;
}
bind ( 'get_user_passport', '_core_for_user_passort' );
/**
 * 定义系统使用的邮件发送器
 *
 * @param IMailer $mailer        	
 * @return IMailer
 */
function _core_for_get_sys_mailer($mailer) {
	if (is_null ( $mailer )) {
		$mailer = new CentImsMailer ();
	}
	return $mailer;
}
bind ( 'get_sys_mailer', '_core_for_get_sys_mailer', 1 );
// base_url
function _core_for_base_url($url) {
	$url = CoreOptionModel::getOption ( 'site_url' );
	if (empty ( $url )) {
		return '/';
	} else {
		return trailingslashit ( $url );
	}
}
bind ( 'get_base_url', '_core_for_base_url' );

include dirname ( __FILE__ ) . DS . 'core_extra_functions.php';